package com.tuju.currency.network;

import android.util.Log;

import com.tuju.currency.bean.resp.WXAccessToken;
import com.tuju.currency.bean.resp.WXUserInfo;
import com.tuju.currency.network.net.BaseReqo;
import com.tuju.currency.network.net.BuildFactory;

import okhttp3.ResponseBody;
import rx.Observable;

/**
 * Created by 彦泽 on 2018/7/26.
 */

public class HttpClient extends BaseReqo {

    private static HttpClient instance;

    public static HttpClient getInstance() {
        if (instance == null) {
            synchronized (HttpClient.class) {
                if (instance == null) {
                    instance = new HttpClient();
                }
            }
        }
        return instance;
    }

    public Observable<Object> requestQuickItem() {
        return transform(BuildFactory.getInstance().create(DataService.class, DataService.API_BASE).requestQuickItem("09K302", "hp"));
    }

    //更新配置文件
    public Observable<ResponseBody> updateConfig() {
        return transform(BuildFactory.getInstance().create(DataService.class, DataService.OSS_BASE).updateConfig("07OU01"));
    }

    public Observable<WXAccessToken> getAccessToken(String appid, String secret, String code) {
        Log.i("yanze", appid + " " + secret + " " + code);
        return transform(BuildFactory.getInstance().create(DataService.class, DataService.WECHAT_API).getAccessToken(appid, secret, code, "authorization_code"));
    }

    public Observable<WXUserInfo> getWXUserInfo(String access_token, String openid) {
        Log.i("yanze", access_token + " " + openid);
        return transform(BuildFactory.getInstance().create(DataService.class, DataService.WECHAT_API).getWXUserInfo(access_token, openid));
    }

}
